<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<script type="text/javascript" language="javascript">
    var daftarsiswaStore = createStoreGroup(false, 'mdaftarsiswaStore',
    ['nis','nama','ayah','ibu','alamat','telepon','seluler','tempat_lahir','tgl_lahir','th_masuk','th_alumni','jenis_kelamin','kd_kelas','kelas','tinggi','berat','tgl_entri','id_user'],
    'kelas' ,'<?php echo base_url(); ?>' + 'base_report/daftar_siswa_rows');
    
    var comboKelasStore_d = createStore(false, 'mcomboKelasStore_d', ['kd_kelas','keterangan'], '<?php echo base_url(); ?>' + 'masterkelas/get_rows_combo');
    
    //===================
    Ext.define('MyTabDaftarSiswa', {
        extend: 'Ext.container.Container',
        xtype: 'TabDaftarSiswa',
        alias: 'widget.TabDaftarSiswa',
        title: 'Daftar Siswa',
        id: 'tab14',
        closable: true,        
        layout: 'border',
        items: [
            {
                xtype: 'panel',
                autoShow: true,
                id: 'paneldaftarsiswa',            
                region: 'center',
                margins: '5 5 5 5',
                layout: 'fit',
                items:[
                    {
                        xtype:'grid',
                        id:'griddaftarsiswa',
                        stateful:true,
                        stateId:'stateGriddaftarsiswa',
                        store: daftarsiswaStore,//Ext.data.StoreManager.lookup('mMasterAccountStore'),
                        stripeRows: true,
                        loadMask: true,
                        //                        sm:sm_masteraccount,
                        columns:[                            
                            {
                                header: "NIS",
                                dataIndex: 'nis',
                                sortable: true,
                                width: 100
                            }
                            ,{
                                header: "Nama Siswa",
                                dataIndex: 'nama',
                                sortable: true,
                                width: 120                                
                            }
                            ,{
                                header: "Nama Ayah",
                                dataIndex: 'ayah',
                                sortable: true,
                                width: 120                                
                            }
                            ,{
                                header: "Nama Ibu",
                                dataIndex: 'ibu',
                                sortable: true,
                                width: 120                                
                            }
                            ,{
                                header: "Alamat",
                                dataIndex: 'alamat',
                                sortable: true,
                                width: 150                                
                            }
                            ,{
                                header: "Telepon",
                                dataIndex: 'telepon',
                                sortable: true,
                                width: 100                                
                            }
                            ,{
                                header: "Seluler",
                                dataIndex: 'seluler',
                                sortable: true,
                                width: 100                                
                            }
                            ,{
                                header: "Tempat Lahir",
                                dataIndex: 'tempat_lahir',
                                sortable: true,
                                width: 120                                
                            }
                            ,{
                                header: "Tanggal Lahir",
                                dataIndex: 'tgl_lahir',
                                sortable: true,
                                width: 80                                
                            }
                            ,{
                                header: "Tahun Masuk",
                                dataIndex: 'th_masuk',
                                sortable: true,
                                width: 80,
                                align:'center'
                            }
                            ,{
                                header: "Tahun Alumni",
                                dataIndex: 'th_alumni',
                                sortable: true,
                                width: 80                                
                                ,align:'center'
                            }
                            ,{
                                header: "L/P",
                                dataIndex: 'jenis_kelamin',
                                sortable: true,
                                width: 50     
                                ,align:'center'
                            }
                            ,{
                                header: "Kelas",
                                dataIndex: 'kelas',
                                sortable: true,
                                width: 60     
                                ,align:'center'
                            }
                            ,{
                                header: "Tinggi",
                                dataIndex: 'tinggi',
                                sortable: true,
                                width: 50  
                                ,align:'right'
                            }
                            ,{
                                header: "Berat",
                                dataIndex: 'berat',
                                sortable: true,
                                width: 50        
                                ,align:'right'
                            }
                           
                        
                        ]
                        ,tbar:{
                            xtype: 'toolbar',
                            padding:'2 0 2 5',
                            items: [
                                {
                                    width: 300,
                                    fieldLabel: 'Cari Nis/Nama Siswa',
                                    labelWidth: 102,
                                    xtype: 'searchfield',
                                    store: daftarsiswaStore,
                                    emptyText: 'Quick Search...'
                                },'-',{
                                    xtype: 'combo',                        
                                    name:'kd_kelas',
                                    //                                    tooltip: 'Field tidak boleh kosong',
                                    //                                    afterLabelTextTpl: required_css,
                                    //                                    fieldLabel: 'Kelas',                        
                                    id: 'daftarsiswa_kd_kelas',
                                    mode:'local',
                                    store: comboKelasStore_d,
                                    valueField: 'kd_kelas',
                                    displayField: 'keterangan',
                                    typeAhead: true,
                                    triggerAction: 'all',                    
                                    //                                    allowBlank: false,
                                    editable: true,                                    
                                    hiddenName: 'kd_kelas',
                                    margins: '0 0 0 5',
                                    emptyText: 'Pilih Kelas',
                                    listeners:{
                                        select:function(cb){
                                            if(cb.getValue()){
                                                var store=Ext.getCmp('griddaftarsiswa').getStore();
                                                store.getProxy().setExtraParam("kelas",cb.getValue());
                                                store.reload(); 
                                            }
                                        }
                                    }
                                },'-'
                                ,{
                                    text: 'Pilih Status',
                                    iconCls: 'icon-list-accept',
                                    menu:[
                                        {
                                            text: 'Semua',
                                            id:'ds_semua',
                                            checked: true,
                                            group: 'alumni',
                                            checkHandler: function(item, checked){
                                                if(checked){
                                                    var store=Ext.getCmp('griddaftarsiswa').getStore();
                                                    store.getProxy().setExtraParam('alumni','all');
                                                    store.reload();
                                                }
                                            }
                                        }, {
                                            text: 'Aktif',
                                            id:'ds_aktif',
                                            checked: false,
                                            group: 'alumni',
                                            checkHandler: function(item, checked){
                                                if(checked){
                                                    var store=Ext.getCmp('griddaftarsiswa').getStore();
                                                    store.getProxy().setExtraParam('alumni','aktif');
                                                    store.reload();
                                                }
                                            }
                                        }, {
                                            text: 'Alumni',
                                            id:'ds_alumni',
                                            checked: false,
                                            group: 'alumni',
                                            checkHandler: function(item, checked){
                                                if(checked){
                                                    var store=Ext.getCmp('griddaftarsiswa').getStore();
                                                    store.getProxy().setExtraParam('alumni','alumni');
                                                    store.reload();
                                                }
                                            }
                                        }
                                    ]
                                },'-'
                                ,{
                                    xtype: 'button',
                                    text: 'Refresh',
                                    iconCls: 'icon-refresh',
                                    onClick: function(){
                                        
                                        Ext.getCmp('daftarsiswa_kd_kelas').setValue('');
                                        Ext.getCmp('ds_semua').setChecked(true);
                                        Ext.getCmp('ds_aktif').setChecked(false);
                                        Ext.getCmp('ds_alumni').setChecked(false);
                                        var store=Ext.getCmp('griddaftarsiswa').getStore();
                                        delete store.getProxy().extraParams['kelas'];                                        
                                        delete store.getProxy().extraParams['alumni'];
                                        
                                        Ext.getCmp('griddaftarsiswa').getStore().load();
                                    }
                                },'-'
                                ,{
                                    xtype: 'button',
                                    text: 'Cetak Pilihan',
                                    iconCls: 'icon-preview_report',
                                    onClick: function(){
                                        var store=Ext.getCmp('griddaftarsiswa').getStore();
                                        var param=(store.getProxy().extraParams);   
                                        var filter=''
                                        var urlset='base_report/daftar_siswa_param';
                                        var urlparam='';
                                        readLog(store.filters.items.length);
                                        if(store.filters.items.length>0 ){
                                            filter=store.filters.items[0].value;
                                            urlparam+='query='+filter;
                                        }
                                        if(param.alumni !== undefined){
                                            if(urlparam.length>0){
                                                urlparam+='&alumni='+param.alumni;
                                            }else{
                                                urlparam+='alumni='+param.alumni;
                                            }
                                        }
                                        if(param.kelas !== undefined){
                                            if(urlparam.length>0){
                                                urlparam+='&kelas='+param.kelas;
                                            }else{
                                                urlparam+='kelas='+param.kelas;
                                            }
                                        }
                                        if(urlparam){
                                            urlset +='?' + urlparam;
                                        }
                                        readLog(urlset);
                                        var winprintsiswa=Ext.create('winprint');
                                        winprintsiswa.show();
                                        to_print('printoutpdf', urlset); 
                                    }
                                },{
                                    xtype: 'button',
                                    text: 'Cetak Siswa Aktif PerKelas',
                                    iconCls: 'icon-preview_report',
                                    onClick: function(){
                                        var kd_kelas=getComp('daftarsiswa_kd_kelas').getValue();
                                        var winprintsiswa=Ext.create('winprint');
                                        winprintsiswa.show();
                                        if(kd_kelas){
                                            to_print('printoutpdf', 'base_report/daftar_siswa_aktif?kelas='+ kd_kelas);    
                                        }else{
                                            to_print('printoutpdf', 'base_report/daftar_siswa_aktif');    
                                        }
                                        

                                        
                                    }
                                }
                                
                            ]
                        }
                        ,bbar:{                        
                            xtype: 'pagingtoolbar',
                            store: daftarsiswaStore,pageSize: ENDPAGE,
                            displayInfo: true
                            //                    plugins: Ext.create('Ext.ux.SlidingPager', {})
                        }
                        ,features:[ {
                                ftype: 'grouping',
                                //                                groupHeaderTpl: '{columnName}: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
                                groupHeaderTpl: '{name}',
                                hideGroupedHeader: true,
                                startCollapsed: false,
                                id: 'daftarsiswa_Grouping'
                            }]

                    }
                ]
            }
        ]
        ,
        listeners:{
            show:function(){
                var storegrid=Ext.getCmp('griddaftarsiswa').store;                
                storegrid.loadPage(1);
                //                comboKelasStore.load();
               
            }
        }
        , initComponent: function() {
            this.callParent(arguments);
        }
    });
</script>